﻿<UserControl x:Class="Songhay.Silverlight.BiggestBox.IndexPart.Views.UserControls.ValidationSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:m="clr-namespace:Songhay.Silverlight.BiggestBox.IndexPart.ViewModels"
    xmlns:vc="clr-namespace:Songhay.ValueConverters;assembly=Songhay.Silverlight"
    Tag="Validation Sample"
    Width="512" Height="300">
    <UserControl.Resources>

        <m:ValidationSampleViewModel x:Key="ValidationSampleViewModelDataSource" d:IsDataSource="True" />

        <vc:BooleanToTextConverter x:Key="BooleanToTextConverterResource" />

        <Style x:Key="StackDataForm" TargetType="StackPanel">
            <Setter Property="StackPanel.Orientation" Value="Horizontal" />
            <Setter Property="FrameworkElement.Margin" Value="16" />
        </Style>
        <Style x:Key="StackLabels" TargetType="StackPanel">
            <Setter Property="FrameworkElement.Width" Value="90" />
        </Style>
        <Style x:Key="StackFields" TargetType="StackPanel">
            <Setter Property="FrameworkElement.Width" Value="256" />
        </Style>
        <Style TargetType="sdk:Label">
            <Setter Property="Height" Value="32" />
            <Setter Property="Margin" Value="0,0,0,4" />
        </Style>
        <Style TargetType="ComboBox">
            <Setter Property="Height" Value="32" />
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Margin" Value="0,0,0,4" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Width" Value="90" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Height" Value="32" />
            <Setter Property="Margin" Value="0,0,0,4" />
        </Style>
    </UserControl.Resources>
    <StackPanel
        DataContext="{StaticResource ValidationSampleViewModelDataSource}"
        Style="{StaticResource StackDataForm}">

        <StackPanel Style="{StaticResource StackLabels}" Width="80">

            <sdk:Label Content="First Name"
                Target="{Binding ElementName=FirstName,
                    Mode=OneWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}" />

            <sdk:Label Content="Last Name"
                Target="{Binding ElementName=LastName,
                    Mode=OneWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}" />

            <sdk:Label Content="Email"
                Target="{Binding ElementName=Email,
                    Mode=OneWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}" />

            <sdk:Label Content="U.S. State"
                Target="{Binding ElementName=USState,
                    Mode=OneWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}" />

        </StackPanel>
        <StackPanel x:Name="FormFields" Style="{StaticResource StackFields}" Width="393">

            <TextBox Name="FirstName"
                Text="{Binding Path=FirstName,
                    Mode=TwoWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}"
                    />

            <TextBox Name="LastName"
                Text="{Binding Path=LastName,
                    Mode=TwoWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}"
                    />

            <TextBox Name="Email"
                Text="{Binding Path=Email,
                    Mode=TwoWay,
                    NotifyOnValidationError=True,
                    UpdateSourceTrigger=Explicit,
                    ValidatesOnExceptions=True}"
                    />


            <StackPanel Orientation="Horizontal">

                <ComboBox Name="USState"
                    ItemsSource="{Binding Path=SelectedUSStates}"
                    SelectedItem="{Binding SelectedUSState,
                        Mode=TwoWay,
                        NotifyOnValidationError=True,
                        UpdateSourceTrigger=Explicit,
                        ValidatesOnExceptions=True}"
                        />

                <sdk:Label Content="In U.S.?"
                    Margin="32,0,16,0"
                    Target="{Binding ElementName=ResidingInUS,
                        Mode=OneWay,
                        NotifyOnValidationError=True,
                        UpdateSourceTrigger=Explicit,
                        ValidatesOnExceptions=True}" />

                <ComboBox Name="ResidingInUS"
                    ItemsSource="{Binding Path=YesNoValues}"
                    SelectedItem="{Binding IsResidingInUS,
                        Converter={StaticResource BooleanToTextConverterResource},
                        Mode=TwoWay,
                        NotifyOnValidationError=True,
                        UpdateSourceTrigger=Explicit,
                        ValidatesOnExceptions=True}"
                        />
            </StackPanel>

            <StackPanel>
                <Button x:Name="Validate"
                    Content="Validate!"
                    Cursor="Hand" HorizontalAlignment="Right"
                    Margin="0,16,0,0"
                    Width="96"
                    />
            </StackPanel>
        </StackPanel>
    </StackPanel>
</UserControl>
